package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.Activity;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.ActivityService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/activity")
public class ActivityController {

    @Autowired
    ActivityService activityService;

    @ApiOperation(value = "新增活动", notes = "新增活动")
    @ApiImplicitParam(name = "activity", value = "活动对象", required = true, dataType = "Object")
    @PostMapping
    public Return saveActivity(Activity activity) {
        Return ret = new Return();
        if(activityService.insert(activity)>0){
            ret.getCommon().setRet(true);
        }
        return ret;

    }
    @ApiOperation(value = "修改活动", notes = "修改活动")
    @ApiImplicitParam(name = "activity", value = "活动对象", required = true, dataType = "Object")
    @PutMapping
    public Return<Activity> update(Activity activity){
        Return<Activity> ret=new Return<>();
        if(activityService.update(activity)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


    @ApiOperation(value = "获取活动列表", notes = "获取活动列表")
    @GetMapping
    public Return<List<Activity>> query(PageInfo pageInfo) {
        Return<List<Activity>> ret = new Return<>();
        List<Activity> activities = activityService.query();
        ret.setData(activities);
        return ret;
    }

    @ApiOperation(value = "获取活动", notes = "获取活动")
    @ApiImplicitParam(name = "activityId", value = "活动ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{activityId}")
    public Return<Activity> gitActivity(@PathVariable(value = "activityId") String activityId) {
        Return<Activity> ret = new Return<>();
        Activity activity = activityService.queryById(activityId);
        ret.setData(activity);
        return ret;
    }


    @ApiOperation(value = "删除活动", notes = "删除活动")
    @ApiImplicitParam(name = "activityIds", value = "活动ID", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{activityIds}")
    public Return<Activity> delete(@PathVariable(value = "activityIds") List<String> activityIds) {
        Return<Activity> ret = new Return<>();
        if(activityService.deleteMore(activityIds)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

}
